<include file="common:header" />
<form id="upForm">
<div class="weui-cells">
	<div class="weui-cell weui-cell_access" style="font-size:20px;color: red;">完善信息</div>

    <!-- 寄语 -->
    <if condition="$info['record_text'] eq null">
      <a class="weui-cell weui-cell_access" href="{:U(MODULE_NAME.'/personal/record',array('ordersn'=>$info['ordersn']))}">
          <div class="weui-cell__bd">
              <p>寄语录音</p>
          </div>
          <div class="weui-cell__ft">前往寄语录音</div>
      </a>
    <else/>
      <div class="weui-cell weui-cell_access">
        <div class="weui-cell__bd">
              <p>寄语录音</p>
          </div>
        <div class="weui-cell__ft">已完成</div>
      </div>
    </if>
    <!-- 寄语 -->

    <div id="datepicker" class="weui-cell weui-cell_access">
        <div class="weui-cell__hd"><label class="weui-label">出生时间</label></div>
        <div class="weui-cell__bd select_bron_time">
          <input type="hidden" id="datetime-picker" name="bron_time" value="{$info['bron_time']|date="Y-m-d H:i",###}">
          <span class="select_time">
            <if condition="$info['bron_time'] eq null">
              未选择
            <else/>
              {$info['bron_time']|date="Y-m-d H:i",###}
            </if>
          </span>
        </div>
    </div>

    <div class="weui-cell weui-cell_access">
        <div class="weui-cell__hd"><label class="weui-label">出生体重（kg）</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" name="baby_weight" placeholder="请输入出生体重" value="{$info['baby_weight']}" <if condition="$info['baby_weight'] neq ''">disabled</if>>
        </div>
    </div>
    <div class="weui-cell weui-cell_access">
        <div class="weui-cell__hd"><label class="weui-label">出生身高（cm）</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" name="baby_height" placeholder="请输入出生身高" value="{$info['baby_height']}"  <if condition="$info['baby_weight'] neq ''">disabled</if>>
        </div>
    </div>
    <div class="weui-cell weui-cell_select weui-cell_select-after">
        <div class="weui-cell__hd">
            <label for="" class="weui-label">宝宝性别</label>
        </div>
        <div class="weui-cell__bd">

           <if condition="$info['baby_weight'] neq ''">
            <select class="weui-select" name="baby_sex" value="{$info['baby_sex']}">
                <option value="0">女</option>
                <option value="1">男</option>
            </select>
          <else/>
              <switch name="$info['baby_sex']" >
                <case value="0">女</case>
                <case value="1">男</case>
              </switch>
          </if>
        </div>
    </div>

    <!-- 预览图片 -->
    <div class="weui-gallery" id="gallery" style="opacity: 0; display: none;">
        <span class="weui-gallery__img" id="galleryImg" style="background-image:url(blob:https://weui.io/3e362d5c-441d-4acc-b328-f872ba290019)"></span>
        <div class="weui-gallery__opr">
            <a href="javascript:" class="weui-gallery__del">
                <!-- <i class="weui-icon-delete weui-icon_gallery-delete"></i> -->
            </a>
        </div>
    </div>
    <!-- 预览图片 -->

    <!-- 图片上传 -->
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <div class="weui-uploader">
                    <div class="weui-uploader__hd">
                        <p class="weui-uploader__title">图片上传(多选)</p>
                        <div class="weui-uploader__info upload_img_num" num="{$info['img_num']}" maxNum="20">{$info['img_num']}/20</div>
                    </div>
                    <div class="weui-uploader__bd">
                        <ul class="weui-uploader__files" id="uploaderFiles">
                          <foreach item="vo" name="info['img_arr']">
                          <li class="weui-uploader__file" style="background-image:url(/upload/{$vo})"></li>
                          </foreach>
                        </ul>
                        <if condition="$type eq 'edit' and $info['img_num'] lt 20">
                          <div class="weui-uploader__input-box">
                            <input type="hidden" name="c_img_num" value="{$info['img_num']}">
                              <input id="uploaderInput" class="weui-uploader__input" type="file" name="photo[]" accept="image/*" multiple="">
                          </div>
                        </if>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 图片上传 -->

   <!-- 下一步 保存或者返回 -->
	<if condition="$type eq 'edit'">
	    <div class="weui-btn-area">
		    <input type="hidden" name="ordersn" value="{$info['ordersn']}"/>
		    <a href="javascript:saveInfo();" class="weui-btn weui-btn_primary">保存(不包括图片)</a>
		  </div>
	</if>

	<div class="weui-btn-area" onclick="window.location.href = '{:U(MODULE_NAME.'/personal/my_baby_order')}';">
	    <a href="javascript:;" class="weui-btn weui-btn_warn">返回</a>
	</div>

</div>
</form>

<div class="weui-cells__title"></div>

<!-- 订单信息 -->
<div class="weui-cells">
	<div class="weui-cell weui-cell_access" style="font-size:20px;color: red;">订单信息</div>
  	<div class="weui-cell">
            <div class="weui-cell__bd">
                <p>订单号</p>
            </div>
            <div class="weui-cell__ft">{$order['ordersn']}</div>
    </div>
    <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>预约时间</p>
            </div>
            <div class="weui-cell__ft">{$order['create_time']|date="Y-m-d H:i:s",###}</div>
    </div>
    <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>预定服务</p>
            </div>
            <div class="weui-cell__ft">宝宝出生视频服务</div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd"><label class="weui-label">所在医院</label></div>
        <div class="weui-cell__ft">
        	{$order['hospital_info']['hospital_name']}
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd"><label class="weui-label">住院编号</label></div>
        <div class="weui-cell__ft">
        	{$order['hospitalno']}
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd"><label class="weui-label">妈妈姓名</label></div>
        <div class="weui-cell__ft">
        	{$info['monther_name']}
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd"><label class="weui-label">爸爸姓名</label></div>
        <div class="weui-cell__ft">
        	{$info['father_name']}
        </div>
    </div>
</div>
<!-- 订单信息 -->

<div class="weui-cells__title"></div>

<!-- 联系人信息 -->
<div class="weui-cells">
	<div class="weui-cell weui-cell_access" style="font-size:20px;color: red;">联系人信息</div>
	<div class="weui-cell">
        <div class="weui-cell__bd">
            <p>联系人</p>
        </div>
        <div class="weui-cell__ft">{$order['parents_name']}</div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <p>联系方式</p>
        </div>
        <div class="weui-cell__ft">{$order['parents_phone']}</div>
    </div>
</div>
<!-- 联系人信息 -->

<div class="weui-cells__title"></div>

<!-- 提取视频 -->
<div class="weui-cells">
	<if condition="$order['is_make'] eq 2">
		<div class="weui-btn-area"><!-- 在线观看 -->
		    <a class="weui-btn weui-btn_primary" href="{:U(MODULE_NAME.'/personal/showVideoOnline',array('ordersn'=>$info['ordersn']))}">在线观看</a>
		</div>
	  	<div class="weui-btn-area show_download_way" num='0'>
	        <input type="hidden" name="ordersn" value=""/>
		    <a  class="weui-btn weui-btn_primary">显示下载方式</a>
		</div>
	</if>

	<!-- 下载提示内容 -->
	<div class="download" style="display:none;padding:10px;">
	1.登录网址：babyvideo.zhfancon.com/download <br />
	2.输入您的视频码与提取码 <br />
	3.点击下载 <br />
	（注：您的视频码是<span style="color:red;">{$order['id']}</span>。 您的提取码是<span style="color:red;">{$order['get_video_num']}</span>）
	</div>
	<!-- 下载提示内容 -->

</div>
<!-- 提取视频 -->

<script type="text/javascript" class="uploader js_show">
$(function(){
    var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)"></li>',
        $gallery = $("#gallery"), $galleryImg = $("#galleryImg"),
        $uploaderInput = $("#uploaderInput"),
        $uploaderFiles = $("#uploaderFiles");


    var maxNum = $('.upload_img_num').attr('maxNum'); //上传最大数量
    $uploaderInput.on("change", function(e){
        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
        var imgNum = $('.upload_img_num').attr('num');    //当前图片数量（上传到服务器才算）
        if(files.length > (maxNum-imgNum)){
    		layer.open({
  				style:'font-size:1.6em;',
  				content:'最多只能上传'+maxNum+'张照片',
  				time:3,
  				end:function(){
  					$('#uploaderInput').val('');
 		 		}
  			});
    		return false;
    	}else{
    		var len = files.length;
    		var lastNum = parseInt(imgNum)+parseInt(len) //当前图片数量 +  添加图片的数量 = 最终准备上传的数量
    		$('.upload_img_num').attr('num',lastNum);
    		$('.upload_img_num').html(lastNum+'/'+maxNum);
    		for (var i = 0; i < len; ++i) {

                var file = files[i];

                if (url) {
                    src = url.createObjectURL(file);
                } else {
                    src = e.target.result;
                }

                $uploaderFiles.append($(tmpl.replace('#url#', src)));
            }
            //选择完毕触发上传操作--上传图片
            saveConfirm();
    	}

    });
    $uploaderFiles.on("click", "li", function(){
        $galleryImg.attr("style", this.getAttribute("style"));
        $gallery.css('opacity',1);
        $gallery.fadeIn(100);
    });
    $gallery.on("click", function(){
        $gallery.fadeOut(100);
    });
});
</script>

<script type="text/javascript">
if('{$type}'=='look'){
	$('input').each(function(){
		$(this).attr('disabled',true);
	});
}


//显示下载方式
$('.show_download_way').click(function(){
	if($(this).attr('num')==0){
		$('.download').slideDown();
		$(this).attr('num','1');
	}else{
		$('.download').slideUp();
		$(this).attr('num','0');
	}
});

//保存前确认  -- 图片素材
function saveConfirm(){
	$.confirm({
	  title: '确认上传？',
	  text: '上传后,不可再次替换。',
	  onOK: function () { //点击确认
        saveInfoFile(); //保存图片素材
	  },
	  onCancel: function () {
	  	location.reload();
	  }
	});
}

//上传图片素材
function saveInfoFile(){
    var formData = new FormData($( "#upForm" )[0]);
    $.ajax({
         url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/save_order_file')}" ,  /*这是处理文件上传的servlet*/
         type: 'POST',
         data : formData,
         async: false,
         cache: false,
         contentType: false,
         processData: false,
         success: function (returndata) {
             if(returndata.status == 1){
                 layer.open({
                    style:'font-size:1.6rem;',
                    content:returndata.info,
                    time:3,
                    end:function(){
                        location.reload();
                    }
                });
             }
         },
    });
}

//完善信息--保存按钮
function saveInfo(){
	var formData = new FormData($( "#upForm" )[0]);
    $.ajax({
         url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/save_order_info')}" ,  /*这是处理文件上传的servlet*/
         type: 'POST',
         data : formData,
         async: false,
         cache: false,
         contentType: false,
         processData: false,
         success: function (returndata) {
        	 if(returndata.status == 1){
        		 layer.open({
      				style:'font-size:1.6rem;',
      				content:returndata.info,
      				time:1.5,
      				end:function(){
     					window.location.href = returndata.url;
     		 		}
      			});
        	 }
         },
    });
}


$('input').each(function(){
	$(this).css('text-align','right');
});

//出生时间
$('.select_bron_time').css('text-align','right');
var date = new Date();
	 var calendar = new datePicker();
	 calendar.init({
	     'trigger': '#datepicker', /*按钮选择器，用于触发弹出插件*/
	     'type': 'datetime',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
	     'minDate':date.toLocaleDateString(),/*最小日期*/
       //'maxDate':new Date().getFullYear()+'-'+(new Date().getMonth()+1)+'-'+new Date().getDate(),/*最大日期*/
	     // 'maxDate':'2050-12-31',/*最大日期*/
	     'onSubmit':function(){
	         var theSelectData=calendar.value;
           $('.select_time').html(theSelectData);
           $('input[name=bron_time]').val(theSelectData);
       },
       onClose:function(){
	   }
	 });
</script>
